<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
		<title>进票管理</title>		
		
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
			<link rel="stylesheet" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
			
			
</head>
<body>
<div id="payment"></div>
<div id="payment1"></div>
<div id="payment2"></div>
<div id="payment3"></div>
</body>
<script type="text/javascript">
Ext.onReady(function(){
	var store = Ext.create('Ext.data.Store', {
		fields: ["check_id","payment_code","check_code","settlement_dept","app_dept_name","is_info_check","is_authentication","is_pay_write"],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>invoiceMgr/intoTicketInfo',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var store1 = Ext.create('Ext.data.Store', {
		fields: ["id","code","crt_date","is_dikou","rcv_date","check_date","now_state"],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>invoiceMgr/findinvoiceInfo',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var store2 = Ext.create('Ext.data.Store', {
		fields: ["fee_id","invoice_code","invoice_item","tax_rate","non_tax_price","value_added_tax"],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>invoiceMgr/findinvoiceItem',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var store3 = Ext.create('Ext.data.Store', {
		fields: ["COST_NAME","BUSINESS_TYPE","BILL_CODE","TAX_PRICE","NON_TAX_PRICE"],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>invoiceMgr/findFeeProject',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var grid = Ext.create('Ext.grid.Panel', {
		renderTo:'payment',
		store: store,
		id:'grid',
		forceFit: true,
		height: 325,
		title:'对应成本信息内容',
		stripeRows:true,
		columnLines: true,
// 		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'check_id', dataIndex: 'check_id',hidden:true},
			{text: '申请单号', dataIndex: 'payment_code'},
			{text: '对账单号', dataIndex: 'check_code'},
			{text: '结算单位', dataIndex: 'settlement_dept', align: 'left'},
			{text: '部门', dataIndex: 'app_dept_name'},
			{text: '是否抵扣', dataIndex: 'is_authentication'},
// 			{text: 'is_info_check', dataIndex: 'is_info_check',hidden:true},
// 			{text: 'is_pay_write', dataIndex: 'is_pay_write',hidden:true},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [
<%-- 			   {text: '否决', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){}} --%>
		],
	listeners: {
		'itemclick': function (view, record, item, index, e) {
			var store = Ext.getCmp('grid1').getStore();
			store.on('beforeload', function(store,options) {  
		            var new_params = {  
		            		check_id:record.data.check_id
		            };  

		            Ext.apply(store.proxy.extraParams,new_params);  
		        });  
		        store.load();  
		}
	},
	});
	var grid1 = Ext.create('Ext.grid.Panel', {
		renderTo:'payment1',
		store: store1,
		id:'grid1',
		forceFit: true,
		height: 325,
		title:'发票信息',
		stripeRows:true,
		columnLines: true,
// 		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'id', dataIndex: 'id',hidden:true},
			{text: '发票号', dataIndex: 'code', align: 'left'},
			{text: '开票时间', dataIndex: 'crt_date', align: 'left'},
// 			{text: '业务类型', dataIndex: 'settlement_dept', align: 'left'},
// 			{text: '结算单位', dataIndex: 'settlement_dept', align: 'left'},
			{text: '是否抵扣', dataIndex: 'is_dikou', align: 'left'},
			{text: '收票时间', dataIndex: 'rcv_date', align: 'left'},
			{text: '核对时间', dataIndex: 'check_date', align: 'left'},
			{text: '目前状态', dataIndex: 'now_state', align: 'left'},
			{text: '交票人', dataIndex: 'now_state', align: 'left'},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store1,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [{text: '信息核对', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
			var records = grid1.getSelectionModel().getSelection();
			   if(records.length==0){
	       			Ext.Msg.alert("提示","请选择需要核对的发票");return;
	       		}
	       		if(records.length>1){
	       			Ext.Msg.alert("提示","只能核对一张发票");return;
	       		}
	       		if(records[0].data.now_state=="已核对"){
	       			Ext.Msg.alert("提示","发票已核对，不能再次核对");return;
	       		}
	       		if(records[0].data.now_state=="已认证抵扣"){
	       			Ext.Msg.alert("提示","发票已认证抵扣，不能再次核对");return;
	       		}
	       		if(records[0].data.now_state=="已核销"){
	       			Ext.Msg.alert("提示","发票已核销，不能再次核对");return;
	       		}
			   Ext.Ajax.request({
					url:'<%=basePath%>invoiceMgr/updateInvoiceInfo',
					params:{
						id:records[0].data.id,now_state:1
					},
					timeout:5000,
					success:function(response){
						store1.load();
						Ext.Msg.alert("成功","核对成功!");
					},
					failure:function(response){
						Ext.Msg.alert("错误","请求异常!");
					}
				});
		}},
		       {text: '发票签收', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png'},
			   {text: '认证抵扣', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
				   var records = grid1.getSelectionModel().getSelection();
				   if(records.length==0){
		       			Ext.Msg.alert("提示","请选择需要认证的发票");return;
		       		}
		       		if(records.length>1){
		       			Ext.Msg.alert("提示","只能认证一张发票");return;
		       		}
		       		if(records[0].data.now_state=="已认证抵扣"){
		       			Ext.Msg.alert("提示","发票已认证抵扣，不能再次认证抵扣");return;
		       		}
		       		if(records[0].data.now_state=="已核销"){
		       			Ext.Msg.alert("提示","发票已核销，不能再次认证抵扣");return;
		       		}
				   Ext.Ajax.request({
						url:'<%=basePath%>invoiceMgr/updateInvoiceInfo',
						params:{
							id:records[0].data.id,now_state:2
						},
						timeout:5000,
						success:function(response){
							store1.load();
							Ext.Msg.alert("成功","认证抵扣成功!");
						},
						failure:function(response){
							Ext.Msg.alert("错误","请求异常!");
						}
					});
			   }},
			   {text: '付款核销', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
				   var records = grid1.getSelectionModel().getSelection();
				   if(records.length==0){
		       			Ext.Msg.alert("提示","请选择需要核销的发票");return;
		       		}
		       		if(records.length>1){
		       			Ext.Msg.alert("提示","只能核销一张发票");return;
		       		}
		       		if(records[0].data.now_state=="已核销"){
		       			Ext.Msg.alert("提示","发票已核销，不能再次核销");return;
		       		}
				   Ext.Ajax.request({
						url:'<%=basePath%>invoiceMgr/updateInvoiceInfo',
						params:{
							id:records[0].data.id,now_state:3
						},
						timeout:5000,
						success:function(response){
							store1.load();
							Ext.Msg.alert("成功","付款核销成功!");
						},
						failure:function(response){
							Ext.Msg.alert("错误","请求异常!");
						}
					});
			   }},
		],
	listeners: {
		'itemclick': function (view, record, item, index, e) {
			var store = Ext.getCmp('grid2').getStore();
			store.on('beforeload', function(store,options) {  
		            var new_params = {  
		            		code:record.data.code
		            };  

		            Ext.apply(store.proxy.extraParams,new_params);  
		        });  
		        store.load();  
		}
	},
	});
	var grid2 = Ext.create('Ext.grid.Panel', {
		renderTo:'payment2',
		store: store2,
		id:'grid2',
		forceFit: true,
		height: 325,
		title:'发票名目',
		stripeRows:true,
		columnLines: true,
// 		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'fee_id', dataIndex: 'fee_id',hidden:true},
			{text: '发票名目', dataIndex: 'invoice_item', align: 'left'},
			{text: '税率', dataIndex: 'tax_rate', align: 'left'},
			{text: '未含税金额', dataIndex: 'non_tax_price', align: 'left'},
			{text: '增值税额', dataIndex: 'value_added_tax', align: 'left'},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store1,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [],
	listeners: {
		'itemclick': function (view, record, item, index, e) {
			var store = Ext.getCmp('grid3').getStore();
			store.on('beforeload', function(store,options) {  
		            var new_params = {  
		            		fee_id:record.data.fee_id
		            };  

		            Ext.apply(store.proxy.extraParams,new_params);  
		        });  
		        store.load();  
		}
	},
	});
	var grid3 = Ext.create('Ext.grid.Panel', {
		renderTo:'payment3',
		store: store3,
		id:'grid3',
		forceFit: true,
		height: 325,
		title:'费用项目',
		stripeRows:true,
		columnLines: true,
// 		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'id', dataIndex: 'id',hidden:true},
			{text: '费用项目', dataIndex: 'COST_NAME', align: 'left'},
			{text: '业务编号', dataIndex: 'BILL_CODE', align: 'left'},
			{text: '业务类型', dataIndex: 'BUSINESS_TYPE', align: 'left'},
			{text: '含税价', dataIndex: 'TAX_PRICE', align: 'left'},
			{text: '不含税价', dataIndex: 'NON_TAX_PRICE', align: 'left'},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store1,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [],
	listeners: {
		'itemclick': function (view, record, item, index, e) {
// 			var store = Ext.getCmp('grid1').getStore();
// 			store.on('beforeload', function(store,options) {  
// 		            var new_params = {  
// 		            		check_code:record.data.check_code
// 		            };  

// 		            Ext.apply(store.proxy.extraParams,new_params);  
// 		        });  
// 		        store.load();  
		}
	},
	});
});

</script>
</html>